package com.chenfan.mcn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.model.McnPage;
import com.chenfan.mcn.model.dto.CustomerTargetDTO;
import com.chenfan.mcn.model.dto.CustomerTargetSearchDTO;
import com.chenfan.mcn.model.vo.CustomerTargetPageVO;
import com.chenfan.mcn.model.vo.QuarterTargetPageVO;
import com.chenfan.mcn.service.CustomerTargetService;
import com.chenfan.privilege.common.config.SearchAuthority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 重点客户目标
 * @author:   tangwei
 * Date:     2021/4/22 10:14
 * Description: 重点客户目标
 */
@RestController
@RequestMapping("/customerTarget")
public class CustomerTargetController {

    @Autowired
    private CustomerTargetService customerTargetService;

    /**
     * 新增
     * @param customerTargetList
     * @return
     */
    @PostMapping("/add")
    public Res<Integer> addTarget(@RequestBody List<CustomerTargetDTO> customerTargetList) {
        return Res.ok(customerTargetService.addTarget(customerTargetList));
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Res<CustomerTargetDTO> targetDetail(@RequestParam Long id) {
        return Res.ok(customerTargetService.targetDetail(id));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Res<Integer> deleteTarget(@RequestParam Long id) {
        return Res.ok(customerTargetService.deleteTarget(id));
    }

    /**
     * 编辑
     * @param customerTargetDTO
     * @return
     */
    @PostMapping("/update")
    public Res<Integer> updateTarget(@RequestBody CustomerTargetDTO customerTargetDTO) {
        return Res.ok(customerTargetService.updateTarget(customerTargetDTO));
    }

    /**
     * 分页列表查询
     * @param mcnPage
     * @param customerTargetSearchDTO
     * @return
     */
    @GetMapping("/customerTargetPage")
    public Res<Page<CustomerTargetPageVO>> customerTargetPage(McnPage<CustomerTargetPageVO> mcnPage, @SearchAuthority CustomerTargetSearchDTO customerTargetSearchDTO) {
        return Res.ok(customerTargetService.customerTargetPage(mcnPage, customerTargetSearchDTO));
    }

    /**
     * 导出
     * @param customerTargetSearchDTO
     * @param response
     */
    @PostMapping("/export")
    public void exportTarget(@SearchAuthority CustomerTargetSearchDTO customerTargetSearchDTO, HttpServletResponse response) {
        customerTargetService.exportTarget(customerTargetSearchDTO, response);
    }

    /**
     * 查看-客户目标指定客户下季度维度分页列表
     * @param mcnPage
     * @param customerId
     * @return
     */
    @GetMapping("/quarterTargetPage")
    public Res<Page<QuarterTargetPageVO>> quarterTargetPage(McnPage<QuarterTargetPageVO> mcnPage, Long customerId) {
        return Res.ok(customerTargetService.quarterTargetPage(mcnPage, customerId));
    }

    /**
     * 导入
     * @param multipartFile
     * @return
     */
    @PostMapping("excel/import")
    public Res<String> excelImport(@RequestParam MultipartFile multipartFile) {
        return Res.ok(customerTargetService.excelImport(multipartFile));
    }

    /**
     * 下载失败原因
     * @param response
     * @param fileId
     */
    @GetMapping("excel/download")
    public void excelDownload(HttpServletResponse response, String fileId) {
        customerTargetService.excelDownload(response, fileId);
    }

}